<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - lcov.info.p - periphery/contracts/rewards/src/periphery/contracts/rewards/RewardsController.sol</title>
  <link rel="stylesheet" type="text/css" href="../../../../../../../gcov.css">
</head>

<body>

          <table width="100%" border=0 cellspacing=0 cellpadding=0>
            <tr><td class="title">LCOV - code coverage report</td></tr>
            <tr><td class="ruler"><img src="../../../../../../../glass.png" width=3 height=3 alt=""></td></tr>

            <tr>
              <td width="100%">
                <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="10%" class="headerValue"><a href="../../../../../../../index.html">top level</a> - <a href="index.html">periphery/contracts/rewards/src/periphery/contracts/rewards</a> - RewardsController.sol<span style="font-size: 80%;"> (source / <a href="RewardsController.sol.func-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="5%"></td>
            <td width="5%" class="headerCovTableHead">Coverage</td>
            <td width="5%" class="headerCovTableHead" title="Covered + Uncovered code">Total</td>
            <td width="5%" class="headerCovTableHead" title="Exercised code only">Hit</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">lcov.info.p</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntryHi">98.7&nbsp;%</td>
            <td class="headerCovTableEntry">79</td>
            <td class="headerCovTableEntry">78</td>
          </tr>
          <tr>
            <td class="headerItem">Test Date:</td>
            <td class="headerValue">2024-04-09 14:12:28</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntryHi">100.0&nbsp;%</td>
            <td class="headerCovTableEntry">23</td>
            <td class="headerCovTableEntry">23</td>
          </tr>
          <tr>
            <td></td>
            <td></td>
            <td></td>
            <td class="headerItem">Branches:</td>
            <td class="headerCovTableEntryHi">-</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">0</td>
          </tr>
                  <tr><td><img src="../../../../../../../glass.png" width=3 height=3 alt=""></td></tr>
                </table>
              </td>
            </tr>

            <tr><td class="ruler"><img src="../../../../../../../glass.png" width=3 height=3 alt=""></td></tr>
          </table>

          <table cellpadding=0 cellspacing=0 border=0>
            <tr>
              <td><br></td>
            </tr>
            <tr>
              <td>
<pre class="sourceHeading">             Branch data     Line data    Source code</pre>
<pre class="source">
<span id="L1"><span class="lineNum">       1</span>                 :             : // SPDX-License-Identifier: BUSL-1.1</span>
<span id="L2"><span class="lineNum">       2</span>                 :             : pragma solidity ^0.8.10;</span>
<span id="L3"><span class="lineNum">       3</span>                 :             : </span>
<span id="L4"><span class="lineNum">       4</span>                 :             : import {VersionedInitializable} from 'aave-v3-core/contracts/protocol/libraries/aave-upgradeability/VersionedInitializable.sol';</span>
<span id="L5"><span class="lineNum">       5</span>                 :             : import {SafeCast} from 'aave-v3-core/contracts/dependencies/openzeppelin/contracts/SafeCast.sol';</span>
<span id="L6"><span class="lineNum">       6</span>                 :             : import {IScaledBalanceToken} from 'aave-v3-core/contracts/interfaces/IScaledBalanceToken.sol';</span>
<span id="L7"><span class="lineNum">       7</span>                 :             : import {RewardsDistributor} from './RewardsDistributor.sol';</span>
<span id="L8"><span class="lineNum">       8</span>                 :             : import {IRewardsController} from './interfaces/IRewardsController.sol';</span>
<span id="L9"><span class="lineNum">       9</span>                 :             : import {ITransferStrategyBase} from './interfaces/ITransferStrategyBase.sol';</span>
<span id="L10"><span class="lineNum">      10</span>                 :             : import {RewardsDataTypes} from './libraries/RewardsDataTypes.sol';</span>
<span id="L11"><span class="lineNum">      11</span>                 :             : import {IEACAggregatorProxy} from '../misc/interfaces/IEACAggregatorProxy.sol';</span>
<span id="L12"><span class="lineNum">      12</span>                 :             : </span>
<span id="L13"><span class="lineNum">      13</span>                 :             : /**</span>
<span id="L14"><span class="lineNum">      14</span>                 :             :  * @title RewardsController</span>
<span id="L15"><span class="lineNum">      15</span>                 :             :  * @notice Abstract contract template to build Distributors contracts for ERC20 rewards to protocol participants</span>
<span id="L16"><span class="lineNum">      16</span>                 :             :  * @author Aave</span>
<span id="L17"><span class="lineNum">      17</span>                 :             :  **/</span>
<span id="L18"><span class="lineNum">      18</span>                 :             : contract RewardsController is RewardsDistributor, VersionedInitializable, IRewardsController {</span>
<span id="L19"><span class="lineNum">      19</span>                 :             :   using SafeCast for uint256;</span>
<span id="L20"><span class="lineNum">      20</span>                 :             : </span>
<span id="L21"><span class="lineNum">      21</span>                 :             :   uint256 public constant REVISION = 1;</span>
<span id="L22"><span class="lineNum">      22</span>                 :             : </span>
<span id="L23"><span class="lineNum">      23</span>                 :             :   // This mapping allows whitelisted addresses to claim on behalf of others</span>
<span id="L24"><span class="lineNum">      24</span>                 :             :   // useful for contracts that hold tokens to be rewarded but don't have any native logic to claim Liquidity Mining rewards</span>
<span id="L25"><span class="lineNum">      25</span>                 :             :   mapping(address =&gt; address) internal _authorizedClaimers;</span>
<span id="L26"><span class="lineNum">      26</span>                 :             : </span>
<span id="L27"><span class="lineNum">      27</span>                 :             :   // reward =&gt; transfer strategy implementation contract</span>
<span id="L28"><span class="lineNum">      28</span>                 :             :   // The TransferStrategy contract abstracts the logic regarding</span>
<span id="L29"><span class="lineNum">      29</span>                 :             :   // the source of the reward and how to transfer it to the user.</span>
<span id="L30"><span class="lineNum">      30</span>                 :             :   mapping(address =&gt; ITransferStrategyBase) internal _transferStrategy;</span>
<span id="L31"><span class="lineNum">      31</span>                 :             : </span>
<span id="L32"><span class="lineNum">      32</span>                 :             :   // This mapping contains the price oracle per reward.</span>
<span id="L33"><span class="lineNum">      33</span>                 :             :   // A price oracle is enforced for integrators to be able to show incentives at</span>
<span id="L34"><span class="lineNum">      34</span>                 :             :   // the current Aave UI without the need to setup an external price registry</span>
<span id="L35"><span class="lineNum">      35</span>                 :             :   // At the moment of reward configuration, the Incentives Controller performs</span>
<span id="L36"><span class="lineNum">      36</span>                 :             :   // a check to see if the provided reward oracle contains `latestAnswer`.</span>
<span id="L37"><span class="lineNum">      37</span>                 :             :   mapping(address =&gt; IEACAggregatorProxy) internal _rewardOracle;</span>
<span id="L38"><span class="lineNum">      38</span>                 :             : </span>
<span id="L39"><span class="lineNum">      39</span>                 :             :   modifier onlyAuthorizedClaimers(address claimer, address user) {</span>
<span id="L40"><span class="lineNum">      40</span>                 :             :     require(_authorizedClaimers[user] == claimer, 'CLAIMER_UNAUTHORIZED');</span>
<span id="L41"><span class="lineNum">      41</span>                 :             :     _;</span>
<span id="L42"><span class="lineNum">      42</span>                 :             :   }</span>
<span id="L43"><span class="lineNum">      43</span>                 :             : </span>
<span id="L44"><span class="lineNum">      44</span>                 :             :   constructor(address emissionManager) RewardsDistributor(emissionManager) {}</span>
<span id="L45"><span class="lineNum">      45</span>                 :             : </span>
<span id="L46"><span class="lineNum">      46</span>                 :             :   /**</span>
<span id="L47"><span class="lineNum">      47</span>                 :             :    * @dev Initialize for RewardsController</span>
<span id="L48"><span class="lineNum">      48</span>                 :             :    * @dev It expects an address as argument since its initialized via PoolAddressesProvider._updateImpl()</span>
<span id="L49"><span class="lineNum">      49</span>                 :             :    **/</span>
<span id="L50"><span class="lineNum">      50</span>                 :<span class="tlaGNC tlaBgGNC">        1231 :   function initialize(address) external initializer {}</span></span>
<span id="L51"><span class="lineNum">      51</span>                 :             : </span>
<span id="L52"><span class="lineNum">      52</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L53"><span class="lineNum">      53</span>                 :<span class="tlaGNC">           2 :   function getClaimer(address user) external view override returns (address) {</span></span>
<span id="L54"><span class="lineNum">      54</span>                 :<span class="tlaGNC">           4 :     return _authorizedClaimers[user];</span></span>
<span id="L55"><span class="lineNum">      55</span>                 :             :   }</span>
<span id="L56"><span class="lineNum">      56</span>                 :             : </span>
<span id="L57"><span class="lineNum">      57</span>                 :             :   /**</span>
<span id="L58"><span class="lineNum">      58</span>                 :             :    * @dev Returns the revision of the implementation contract</span>
<span id="L59"><span class="lineNum">      59</span>                 :             :    * @return uint256, current revision version</span>
<span id="L60"><span class="lineNum">      60</span>                 :             :    */</span>
<span id="L61"><span class="lineNum">      61</span>                 :<span class="tlaGNC">        1231 :   function getRevision() internal pure override returns (uint256) {</span></span>
<span id="L62"><span class="lineNum">      62</span>                 :<span class="tlaGNC">        2462 :     return REVISION;</span></span>
<span id="L63"><span class="lineNum">      63</span>                 :             :   }</span>
<span id="L64"><span class="lineNum">      64</span>                 :             : </span>
<span id="L65"><span class="lineNum">      65</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L66"><span class="lineNum">      66</span>                 :<span class="tlaGNC">           1 :   function getRewardOracle(address reward) external view override returns (address) {</span></span>
<span id="L67"><span class="lineNum">      67</span>                 :<span class="tlaGNC">           3 :     return address(_rewardOracle[reward]);</span></span>
<span id="L68"><span class="lineNum">      68</span>                 :             :   }</span>
<span id="L69"><span class="lineNum">      69</span>                 :             : </span>
<span id="L70"><span class="lineNum">      70</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L71"><span class="lineNum">      71</span>                 :<span class="tlaGNC">           1 :   function getTransferStrategy(address reward) external view override returns (address) {</span></span>
<span id="L72"><span class="lineNum">      72</span>                 :<span class="tlaGNC">           3 :     return address(_transferStrategy[reward]);</span></span>
<span id="L73"><span class="lineNum">      73</span>                 :             :   }</span>
<span id="L74"><span class="lineNum">      74</span>                 :             : </span>
<span id="L75"><span class="lineNum">      75</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L76"><span class="lineNum">      76</span>                 :<span class="tlaGNC">          20 :   function configureAssets(</span></span>
<span id="L77"><span class="lineNum">      77</span>                 :             :     RewardsDataTypes.RewardsConfigInput[] memory config</span>
<span id="L78"><span class="lineNum">      78</span>                 :             :   ) external override onlyEmissionManager {</span>
<span id="L79"><span class="lineNum">      79</span>                 :<span class="tlaGNC">         100 :     for (uint256 i = 0; i &lt; config.length; i++) {</span></span>
<span id="L80"><span class="lineNum">      80</span>                 :             :       // Get the current Scaled Total Supply of AToken or Debt token</span>
<span id="L81"><span class="lineNum">      81</span>                 :<span class="tlaGNC">          40 :       config[i].totalSupply = IScaledBalanceToken(config[i].asset).scaledTotalSupply();</span></span>
<span id="L82"><span class="lineNum">      82</span>                 :             : </span>
<span id="L83"><span class="lineNum">      83</span>                 :             :       // Install TransferStrategy logic at IncentivesController</span>
<span id="L84"><span class="lineNum">      84</span>                 :<span class="tlaGNC">          40 :       _installTransferStrategy(config[i].reward, config[i].transferStrategy);</span></span>
<span id="L85"><span class="lineNum">      85</span>                 :             : </span>
<span id="L86"><span class="lineNum">      86</span>                 :             :       // Set reward oracle, enforces input oracle to have latestPrice function</span>
<span id="L87"><span class="lineNum">      87</span>                 :<span class="tlaGNC">          40 :       _setRewardOracle(config[i].reward, config[i].rewardOracle);</span></span>
<span id="L88"><span class="lineNum">      88</span>                 :             :     }</span>
<span id="L89"><span class="lineNum">      89</span>                 :<span class="tlaGNC">          40 :     _configureAssets(config);</span></span>
<span id="L90"><span class="lineNum">      90</span>                 :             :   }</span>
<span id="L91"><span class="lineNum">      91</span>                 :             : </span>
<span id="L92"><span class="lineNum">      92</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L93"><span class="lineNum">      93</span>                 :<span class="tlaGNC">           2 :   function setTransferStrategy(</span></span>
<span id="L94"><span class="lineNum">      94</span>                 :             :     address reward,</span>
<span id="L95"><span class="lineNum">      95</span>                 :             :     ITransferStrategyBase transferStrategy</span>
<span id="L96"><span class="lineNum">      96</span>                 :             :   ) external onlyEmissionManager {</span>
<span id="L97"><span class="lineNum">      97</span>                 :<span class="tlaGNC">           4 :     _installTransferStrategy(reward, transferStrategy);</span></span>
<span id="L98"><span class="lineNum">      98</span>                 :             :   }</span>
<span id="L99"><span class="lineNum">      99</span>                 :             : </span>
<span id="L100"><span class="lineNum">     100</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L101"><span class="lineNum">     101</span>                 :<span class="tlaGNC">           2 :   function setRewardOracle(</span></span>
<span id="L102"><span class="lineNum">     102</span>                 :             :     address reward,</span>
<span id="L103"><span class="lineNum">     103</span>                 :             :     IEACAggregatorProxy rewardOracle</span>
<span id="L104"><span class="lineNum">     104</span>                 :             :   ) external onlyEmissionManager {</span>
<span id="L105"><span class="lineNum">     105</span>                 :<span class="tlaGNC">           4 :     _setRewardOracle(reward, rewardOracle);</span></span>
<span id="L106"><span class="lineNum">     106</span>                 :             :   }</span>
<span id="L107"><span class="lineNum">     107</span>                 :             : </span>
<span id="L108"><span class="lineNum">     108</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L109"><span class="lineNum">     109</span>                 :<span class="tlaGNC">       53887 :   function handleAction(address user, uint256 totalSupply, uint256 userBalance) external override {</span></span>
<span id="L110"><span class="lineNum">     110</span>                 :<span class="tlaGNC">      107774 :     _updateData(msg.sender, user, userBalance, totalSupply);</span></span>
<span id="L111"><span class="lineNum">     111</span>                 :             :   }</span>
<span id="L112"><span class="lineNum">     112</span>                 :             : </span>
<span id="L113"><span class="lineNum">     113</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L114"><span class="lineNum">     114</span>                 :<span class="tlaGNC">           4 :   function claimRewards(</span></span>
<span id="L115"><span class="lineNum">     115</span>                 :             :     address[] calldata assets,</span>
<span id="L116"><span class="lineNum">     116</span>                 :             :     uint256 amount,</span>
<span id="L117"><span class="lineNum">     117</span>                 :             :     address to,</span>
<span id="L118"><span class="lineNum">     118</span>                 :             :     address reward</span>
<span id="L119"><span class="lineNum">     119</span>                 :             :   ) external override returns (uint256) {</span>
<span id="L120"><span class="lineNum">     120</span>                 :<span class="tlaGNC">           8 :     require(to != address(0), 'INVALID_TO_ADDRESS');</span></span>
<span id="L121"><span class="lineNum">     121</span>                 :<span class="tlaGNC">          12 :     return _claimRewards(assets, amount, msg.sender, msg.sender, to, reward);</span></span>
<span id="L122"><span class="lineNum">     122</span>                 :             :   }</span>
<span id="L123"><span class="lineNum">     123</span>                 :             : </span>
<span id="L124"><span class="lineNum">     124</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L125"><span class="lineNum">     125</span>                 :<span class="tlaGNC">           1 :   function claimRewardsOnBehalf(</span></span>
<span id="L126"><span class="lineNum">     126</span>                 :             :     address[] calldata assets,</span>
<span id="L127"><span class="lineNum">     127</span>                 :             :     uint256 amount,</span>
<span id="L128"><span class="lineNum">     128</span>                 :             :     address user,</span>
<span id="L129"><span class="lineNum">     129</span>                 :             :     address to,</span>
<span id="L130"><span class="lineNum">     130</span>                 :             :     address reward</span>
<span id="L131"><span class="lineNum">     131</span>                 :             :   ) external override onlyAuthorizedClaimers(msg.sender, user) returns (uint256) {</span>
<span id="L132"><span class="lineNum">     132</span>                 :<span class="tlaGNC">           2 :     require(user != address(0), 'INVALID_USER_ADDRESS');</span></span>
<span id="L133"><span class="lineNum">     133</span>                 :<span class="tlaGNC">           2 :     require(to != address(0), 'INVALID_TO_ADDRESS');</span></span>
<span id="L134"><span class="lineNum">     134</span>                 :<span class="tlaGNC">           3 :     return _claimRewards(assets, amount, msg.sender, user, to, reward);</span></span>
<span id="L135"><span class="lineNum">     135</span>                 :             :   }</span>
<span id="L136"><span class="lineNum">     136</span>                 :             : </span>
<span id="L137"><span class="lineNum">     137</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L138"><span class="lineNum">     138</span>                 :<span class="tlaGNC">           1 :   function claimRewardsToSelf(</span></span>
<span id="L139"><span class="lineNum">     139</span>                 :             :     address[] calldata assets,</span>
<span id="L140"><span class="lineNum">     140</span>                 :             :     uint256 amount,</span>
<span id="L141"><span class="lineNum">     141</span>                 :             :     address reward</span>
<span id="L142"><span class="lineNum">     142</span>                 :             :   ) external override returns (uint256) {</span>
<span id="L143"><span class="lineNum">     143</span>                 :<span class="tlaGNC">           3 :     return _claimRewards(assets, amount, msg.sender, msg.sender, msg.sender, reward);</span></span>
<span id="L144"><span class="lineNum">     144</span>                 :             :   }</span>
<span id="L145"><span class="lineNum">     145</span>                 :             : </span>
<span id="L146"><span class="lineNum">     146</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L147"><span class="lineNum">     147</span>                 :<span class="tlaGNC">           1 :   function claimAllRewards(</span></span>
<span id="L148"><span class="lineNum">     148</span>                 :             :     address[] calldata assets,</span>
<span id="L149"><span class="lineNum">     149</span>                 :             :     address to</span>
<span id="L150"><span class="lineNum">     150</span>                 :             :   ) external override returns (address[] memory rewardsList, uint256[] memory claimedAmounts) {</span>
<span id="L151"><span class="lineNum">     151</span>                 :<span class="tlaGNC">           2 :     require(to != address(0), 'INVALID_TO_ADDRESS');</span></span>
<span id="L152"><span class="lineNum">     152</span>                 :<span class="tlaGNC">           3 :     return _claimAllRewards(assets, msg.sender, msg.sender, to);</span></span>
<span id="L153"><span class="lineNum">     153</span>                 :             :   }</span>
<span id="L154"><span class="lineNum">     154</span>                 :             : </span>
<span id="L155"><span class="lineNum">     155</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L156"><span class="lineNum">     156</span>                 :<span class="tlaGNC">           1 :   function claimAllRewardsOnBehalf(</span></span>
<span id="L157"><span class="lineNum">     157</span>                 :             :     address[] calldata assets,</span>
<span id="L158"><span class="lineNum">     158</span>                 :             :     address user,</span>
<span id="L159"><span class="lineNum">     159</span>                 :             :     address to</span>
<span id="L160"><span class="lineNum">     160</span>                 :             :   )</span>
<span id="L161"><span class="lineNum">     161</span>                 :             :     external</span>
<span id="L162"><span class="lineNum">     162</span>                 :             :     override</span>
<span id="L163"><span class="lineNum">     163</span>                 :             :     onlyAuthorizedClaimers(msg.sender, user)</span>
<span id="L164"><span class="lineNum">     164</span>                 :             :     returns (address[] memory rewardsList, uint256[] memory claimedAmounts)</span>
<span id="L165"><span class="lineNum">     165</span>                 :             :   {</span>
<span id="L166"><span class="lineNum">     166</span>                 :<span class="tlaGNC">           2 :     require(user != address(0), 'INVALID_USER_ADDRESS');</span></span>
<span id="L167"><span class="lineNum">     167</span>                 :<span class="tlaGNC">           2 :     require(to != address(0), 'INVALID_TO_ADDRESS');</span></span>
<span id="L168"><span class="lineNum">     168</span>                 :<span class="tlaGNC">           3 :     return _claimAllRewards(assets, msg.sender, user, to);</span></span>
<span id="L169"><span class="lineNum">     169</span>                 :             :   }</span>
<span id="L170"><span class="lineNum">     170</span>                 :             : </span>
<span id="L171"><span class="lineNum">     171</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L172"><span class="lineNum">     172</span>                 :<span class="tlaGNC">           1 :   function claimAllRewardsToSelf(</span></span>
<span id="L173"><span class="lineNum">     173</span>                 :             :     address[] calldata assets</span>
<span id="L174"><span class="lineNum">     174</span>                 :             :   ) external override returns (address[] memory rewardsList, uint256[] memory claimedAmounts) {</span>
<span id="L175"><span class="lineNum">     175</span>                 :<span class="tlaGNC">           3 :     return _claimAllRewards(assets, msg.sender, msg.sender, msg.sender);</span></span>
<span id="L176"><span class="lineNum">     176</span>                 :             :   }</span>
<span id="L177"><span class="lineNum">     177</span>                 :             : </span>
<span id="L178"><span class="lineNum">     178</span>                 :             :   /// @inheritdoc IRewardsController</span>
<span id="L179"><span class="lineNum">     179</span>                 :<span class="tlaGNC">           4 :   function setClaimer(address user, address caller) external override onlyEmissionManager {</span></span>
<span id="L180"><span class="lineNum">     180</span>                 :<span class="tlaGNC">           8 :     _authorizedClaimers[user] = caller;</span></span>
<span id="L181"><span class="lineNum">     181</span>                 :<span class="tlaGNC">           8 :     emit ClaimerSet(user, caller);</span></span>
<span id="L182"><span class="lineNum">     182</span>                 :             :   }</span>
<span id="L183"><span class="lineNum">     183</span>                 :             : </span>
<span id="L184"><span class="lineNum">     184</span>                 :             :   /**</span>
<span id="L185"><span class="lineNum">     185</span>                 :             :    * @dev Get user balances and total supply of all the assets specified by the assets parameter</span>
<span id="L186"><span class="lineNum">     186</span>                 :             :    * @param assets List of assets to retrieve user balance and total supply</span>
<span id="L187"><span class="lineNum">     187</span>                 :             :    * @param user Address of the user</span>
<span id="L188"><span class="lineNum">     188</span>                 :             :    * @return userAssetBalances contains a list of structs with user balance and total supply of the given assets</span>
<span id="L189"><span class="lineNum">     189</span>                 :             :    */</span>
<span id="L190"><span class="lineNum">     190</span>                 :<span class="tlaGNC">          19 :   function _getUserAssetBalances(</span></span>
<span id="L191"><span class="lineNum">     191</span>                 :             :     address[] calldata assets,</span>
<span id="L192"><span class="lineNum">     192</span>                 :             :     address user</span>
<span id="L193"><span class="lineNum">     193</span>                 :             :   ) internal view override returns (RewardsDataTypes.UserAssetBalance[] memory userAssetBalances) {</span>
<span id="L194"><span class="lineNum">     194</span>                 :<span class="tlaGNC">          38 :     userAssetBalances = new RewardsDataTypes.UserAssetBalance[](assets.length);</span></span>
<span id="L195"><span class="lineNum">     195</span>                 :<span class="tlaGNC">          95 :     for (uint256 i = 0; i &lt; assets.length; i++) {</span></span>
<span id="L196"><span class="lineNum">     196</span>                 :<span class="tlaGNC">          38 :       userAssetBalances[i].asset = assets[i];</span></span>
<span id="L197"><span class="lineNum">     197</span>                 :<span class="tlaGNC">          38 :       (userAssetBalances[i].userBalance, userAssetBalances[i].totalSupply) = IScaledBalanceToken(</span></span>
<span id="L198"><span class="lineNum">     198</span>                 :             :         assets[i]</span>
<span id="L199"><span class="lineNum">     199</span>                 :             :       ).getScaledUserBalanceAndSupply(user);</span>
<span id="L200"><span class="lineNum">     200</span>                 :             :     }</span>
<span id="L201"><span class="lineNum">     201</span>                 :<span class="tlaUNC tlaBgUNC">           0 :     return userAssetBalances;</span></span>
<span id="L202"><span class="lineNum">     202</span>                 :             :   }</span>
<span id="L203"><span class="lineNum">     203</span>                 :             : </span>
<span id="L204"><span class="lineNum">     204</span>                 :             :   /**</span>
<span id="L205"><span class="lineNum">     205</span>                 :             :    * @dev Claims one type of reward for a user on behalf, on all the assets of the pool, accumulating the pending rewards.</span>
<span id="L206"><span class="lineNum">     206</span>                 :             :    * @param assets List of assets to check eligible distributions before claiming rewards</span>
<span id="L207"><span class="lineNum">     207</span>                 :             :    * @param amount Amount of rewards to claim</span>
<span id="L208"><span class="lineNum">     208</span>                 :             :    * @param claimer Address of the claimer who claims rewards on behalf of user</span>
<span id="L209"><span class="lineNum">     209</span>                 :             :    * @param user Address to check and claim rewards</span>
<span id="L210"><span class="lineNum">     210</span>                 :             :    * @param to Address that will be receiving the rewards</span>
<span id="L211"><span class="lineNum">     211</span>                 :             :    * @param reward Address of the reward token</span>
<span id="L212"><span class="lineNum">     212</span>                 :             :    * @return Rewards claimed</span>
<span id="L213"><span class="lineNum">     213</span>                 :             :    **/</span>
<span id="L214"><span class="lineNum">     214</span>                 :<span class="tlaGNC tlaBgGNC">           6 :   function _claimRewards(</span></span>
<span id="L215"><span class="lineNum">     215</span>                 :             :     address[] calldata assets,</span>
<span id="L216"><span class="lineNum">     216</span>                 :             :     uint256 amount,</span>
<span id="L217"><span class="lineNum">     217</span>                 :             :     address claimer,</span>
<span id="L218"><span class="lineNum">     218</span>                 :             :     address user,</span>
<span id="L219"><span class="lineNum">     219</span>                 :             :     address to,</span>
<span id="L220"><span class="lineNum">     220</span>                 :             :     address reward</span>
<span id="L221"><span class="lineNum">     221</span>                 :             :   ) internal returns (uint256) {</span>
<span id="L222"><span class="lineNum">     222</span>                 :<span class="tlaGNC">          12 :     if (amount == 0) {</span></span>
<span id="L223"><span class="lineNum">     223</span>                 :<span class="tlaGNC">           2 :       return 0;</span></span>
<span id="L224"><span class="lineNum">     224</span>                 :             :     }</span>
<span id="L225"><span class="lineNum">     225</span>                 :<span class="tlaGNC">          10 :     uint256 totalRewards;</span></span>
<span id="L226"><span class="lineNum">     226</span>                 :             : </span>
<span id="L227"><span class="lineNum">     227</span>                 :<span class="tlaGNC">          10 :     _updateDataMultiple(user, _getUserAssetBalances(assets, user));</span></span>
<span id="L228"><span class="lineNum">     228</span>                 :<span class="tlaGNC">          23 :     for (uint256 i = 0; i &lt; assets.length; i++) {</span></span>
<span id="L229"><span class="lineNum">     229</span>                 :<span class="tlaGNC">          10 :       address asset = assets[i];</span></span>
<span id="L230"><span class="lineNum">     230</span>                 :<span class="tlaGNC">          10 :       totalRewards += _assets[asset].rewards[reward].usersData[user].accrued;</span></span>
<span id="L231"><span class="lineNum">     231</span>                 :             : </span>
<span id="L232"><span class="lineNum">     232</span>                 :<span class="tlaGNC">          10 :       if (totalRewards &lt;= amount) {</span></span>
<span id="L233"><span class="lineNum">     233</span>                 :<span class="tlaGNC">           8 :         _assets[asset].rewards[reward].usersData[user].accrued = 0;</span></span>
<span id="L234"><span class="lineNum">     234</span>                 :             :       } else {</span>
<span id="L235"><span class="lineNum">     235</span>                 :<span class="tlaGNC">           3 :         uint256 difference = totalRewards - amount;</span></span>
<span id="L236"><span class="lineNum">     236</span>                 :<span class="tlaGNC">           2 :         totalRewards -= difference;</span></span>
<span id="L237"><span class="lineNum">     237</span>                 :<span class="tlaGNC">           2 :         _assets[asset].rewards[reward].usersData[user].accrued = difference.toUint128();</span></span>
<span id="L238"><span class="lineNum">     238</span>                 :<span class="tlaGNC">           2 :         break;</span></span>
<span id="L239"><span class="lineNum">     239</span>                 :             :       }</span>
<span id="L240"><span class="lineNum">     240</span>                 :             :     }</span>
<span id="L241"><span class="lineNum">     241</span>                 :             : </span>
<span id="L242"><span class="lineNum">     242</span>                 :<span class="tlaGNC">          10 :     if (totalRewards == 0) {</span></span>
<span id="L243"><span class="lineNum">     243</span>                 :<span class="tlaGNC">           2 :       return 0;</span></span>
<span id="L244"><span class="lineNum">     244</span>                 :             :     }</span>
<span id="L245"><span class="lineNum">     245</span>                 :             : </span>
<span id="L246"><span class="lineNum">     246</span>                 :<span class="tlaGNC">           8 :     _transferRewards(to, reward, totalRewards);</span></span>
<span id="L247"><span class="lineNum">     247</span>                 :<span class="tlaGNC">           8 :     emit RewardsClaimed(user, reward, to, claimer, totalRewards);</span></span>
<span id="L248"><span class="lineNum">     248</span>                 :             : </span>
<span id="L249"><span class="lineNum">     249</span>                 :<span class="tlaGNC">           8 :     return totalRewards;</span></span>
<span id="L250"><span class="lineNum">     250</span>                 :             :   }</span>
<span id="L251"><span class="lineNum">     251</span>                 :             : </span>
<span id="L252"><span class="lineNum">     252</span>                 :             :   /**</span>
<span id="L253"><span class="lineNum">     253</span>                 :             :    * @dev Claims one type of reward for a user on behalf, on all the assets of the pool, accumulating the pending rewards.</span>
<span id="L254"><span class="lineNum">     254</span>                 :             :    * @param assets List of assets to check eligible distributions before claiming rewards</span>
<span id="L255"><span class="lineNum">     255</span>                 :             :    * @param claimer Address of the claimer on behalf of user</span>
<span id="L256"><span class="lineNum">     256</span>                 :             :    * @param user Address to check and claim rewards</span>
<span id="L257"><span class="lineNum">     257</span>                 :             :    * @param to Address that will be receiving the rewards</span>
<span id="L258"><span class="lineNum">     258</span>                 :             :    * @return</span>
<span id="L259"><span class="lineNum">     259</span>                 :             :    *   rewardsList List of reward addresses</span>
<span id="L260"><span class="lineNum">     260</span>                 :             :    *   claimedAmount List of claimed amounts, follows &quot;rewardsList&quot; items order</span>
<span id="L261"><span class="lineNum">     261</span>                 :             :    **/</span>
<span id="L262"><span class="lineNum">     262</span>                 :<span class="tlaGNC">           3 :   function _claimAllRewards(</span></span>
<span id="L263"><span class="lineNum">     263</span>                 :             :     address[] calldata assets,</span>
<span id="L264"><span class="lineNum">     264</span>                 :             :     address claimer,</span>
<span id="L265"><span class="lineNum">     265</span>                 :             :     address user,</span>
<span id="L266"><span class="lineNum">     266</span>                 :             :     address to</span>
<span id="L267"><span class="lineNum">     267</span>                 :             :   ) internal returns (address[] memory rewardsList, uint256[] memory claimedAmounts) {</span>
<span id="L268"><span class="lineNum">     268</span>                 :<span class="tlaGNC">           6 :     uint256 rewardsListLength = _rewardsList.length;</span></span>
<span id="L269"><span class="lineNum">     269</span>                 :<span class="tlaGNC">           6 :     rewardsList = new address[](rewardsListLength);</span></span>
<span id="L270"><span class="lineNum">     270</span>                 :<span class="tlaGNC">           6 :     claimedAmounts = new uint256[](rewardsListLength);</span></span>
<span id="L271"><span class="lineNum">     271</span>                 :             : </span>
<span id="L272"><span class="lineNum">     272</span>                 :<span class="tlaGNC">           6 :     _updateDataMultiple(user, _getUserAssetBalances(assets, user));</span></span>
<span id="L273"><span class="lineNum">     273</span>                 :             : </span>
<span id="L274"><span class="lineNum">     274</span>                 :<span class="tlaGNC">          15 :     for (uint256 i = 0; i &lt; assets.length; i++) {</span></span>
<span id="L275"><span class="lineNum">     275</span>                 :<span class="tlaGNC">           6 :       address asset = assets[i];</span></span>
<span id="L276"><span class="lineNum">     276</span>                 :<span class="tlaGNC">          15 :       for (uint256 j = 0; j &lt; rewardsListLength; j++) {</span></span>
<span id="L277"><span class="lineNum">     277</span>                 :<span class="tlaGNC">           9 :         if (rewardsList[j] == address(0)) {</span></span>
<span id="L278"><span class="lineNum">     278</span>                 :<span class="tlaGNC">           6 :           rewardsList[j] = _rewardsList[j];</span></span>
<span id="L279"><span class="lineNum">     279</span>                 :             :         }</span>
<span id="L280"><span class="lineNum">     280</span>                 :<span class="tlaGNC">           6 :         uint256 rewardAmount = _assets[asset].rewards[rewardsList[j]].usersData[user].accrued;</span></span>
<span id="L281"><span class="lineNum">     281</span>                 :<span class="tlaGNC">           6 :         if (rewardAmount != 0) {</span></span>
<span id="L282"><span class="lineNum">     282</span>                 :<span class="tlaGNC">           6 :           claimedAmounts[j] += rewardAmount;</span></span>
<span id="L283"><span class="lineNum">     283</span>                 :<span class="tlaGNC">           6 :           _assets[asset].rewards[rewardsList[j]].usersData[user].accrued = 0;</span></span>
<span id="L284"><span class="lineNum">     284</span>                 :             :         }</span>
<span id="L285"><span class="lineNum">     285</span>                 :             :       }</span>
<span id="L286"><span class="lineNum">     286</span>                 :             :     }</span>
<span id="L287"><span class="lineNum">     287</span>                 :<span class="tlaGNC">          15 :     for (uint256 i = 0; i &lt; rewardsListLength; i++) {</span></span>
<span id="L288"><span class="lineNum">     288</span>                 :<span class="tlaGNC">           6 :       _transferRewards(to, rewardsList[i], claimedAmounts[i]);</span></span>
<span id="L289"><span class="lineNum">     289</span>                 :<span class="tlaGNC">           6 :       emit RewardsClaimed(user, rewardsList[i], to, claimer, claimedAmounts[i]);</span></span>
<span id="L290"><span class="lineNum">     290</span>                 :             :     }</span>
<span id="L291"><span class="lineNum">     291</span>                 :<span class="tlaGNC">           6 :     return (rewardsList, claimedAmounts);</span></span>
<span id="L292"><span class="lineNum">     292</span>                 :             :   }</span>
<span id="L293"><span class="lineNum">     293</span>                 :             : </span>
<span id="L294"><span class="lineNum">     294</span>                 :             :   /**</span>
<span id="L295"><span class="lineNum">     295</span>                 :             :    * @dev Function to transfer rewards to the desired account using delegatecall and</span>
<span id="L296"><span class="lineNum">     296</span>                 :             :    * @param to Account address to send the rewards</span>
<span id="L297"><span class="lineNum">     297</span>                 :             :    * @param reward Address of the reward token</span>
<span id="L298"><span class="lineNum">     298</span>                 :             :    * @param amount Amount of rewards to transfer</span>
<span id="L299"><span class="lineNum">     299</span>                 :             :    */</span>
<span id="L300"><span class="lineNum">     300</span>                 :<span class="tlaGNC">           7 :   function _transferRewards(address to, address reward, uint256 amount) internal {</span></span>
<span id="L301"><span class="lineNum">     301</span>                 :<span class="tlaGNC">          14 :     ITransferStrategyBase transferStrategy = _transferStrategy[reward];</span></span>
<span id="L302"><span class="lineNum">     302</span>                 :             : </span>
<span id="L303"><span class="lineNum">     303</span>                 :<span class="tlaGNC">          21 :     bool success = transferStrategy.performTransfer(to, reward, amount);</span></span>
<span id="L304"><span class="lineNum">     304</span>                 :             : </span>
<span id="L305"><span class="lineNum">     305</span>                 :<span class="tlaGNC">          14 :     require(success == true, 'TRANSFER_ERROR');</span></span>
<span id="L306"><span class="lineNum">     306</span>                 :             :   }</span>
<span id="L307"><span class="lineNum">     307</span>                 :             : </span>
<span id="L308"><span class="lineNum">     308</span>                 :             :   /**</span>
<span id="L309"><span class="lineNum">     309</span>                 :             :    * @dev Returns true if `account` is a contract.</span>
<span id="L310"><span class="lineNum">     310</span>                 :             :    * @param account The address of the account</span>
<span id="L311"><span class="lineNum">     311</span>                 :             :    * @return bool, true if contract, false otherwise</span>
<span id="L312"><span class="lineNum">     312</span>                 :             :    */</span>
<span id="L313"><span class="lineNum">     313</span>                 :<span class="tlaGNC">          22 :   function _isContract(address account) internal view returns (bool) {</span></span>
<span id="L314"><span class="lineNum">     314</span>                 :             :     // This method relies on extcodesize, which returns 0 for contracts in</span>
<span id="L315"><span class="lineNum">     315</span>                 :             :     // construction, since the code is only stored at the end of the</span>
<span id="L316"><span class="lineNum">     316</span>                 :             :     // constructor execution.</span>
<span id="L317"><span class="lineNum">     317</span>                 :             : </span>
<span id="L318"><span class="lineNum">     318</span>                 :<span class="tlaGNC">          44 :     uint256 size;</span></span>
<span id="L319"><span class="lineNum">     319</span>                 :             :     // solhint-disable-next-line no-inline-assembly</span>
<span id="L320"><span class="lineNum">     320</span>                 :             :     assembly {</span>
<span id="L321"><span class="lineNum">     321</span>                 :<span class="tlaGNC">          44 :       size := extcodesize(account)</span></span>
<span id="L322"><span class="lineNum">     322</span>                 :             :     }</span>
<span id="L323"><span class="lineNum">     323</span>                 :<span class="tlaGNC">          66 :     return size &gt; 0;</span></span>
<span id="L324"><span class="lineNum">     324</span>                 :             :   }</span>
<span id="L325"><span class="lineNum">     325</span>                 :             : </span>
<span id="L326"><span class="lineNum">     326</span>                 :             :   /**</span>
<span id="L327"><span class="lineNum">     327</span>                 :             :    * @dev Internal function to call the optional install hook at the TransferStrategy</span>
<span id="L328"><span class="lineNum">     328</span>                 :             :    * @param reward The address of the reward token</span>
<span id="L329"><span class="lineNum">     329</span>                 :             :    * @param transferStrategy The address of the reward TransferStrategy</span>
<span id="L330"><span class="lineNum">     330</span>                 :             :    */</span>
<span id="L331"><span class="lineNum">     331</span>                 :<span class="tlaGNC">          22 :   function _installTransferStrategy(</span></span>
<span id="L332"><span class="lineNum">     332</span>                 :             :     address reward,</span>
<span id="L333"><span class="lineNum">     333</span>                 :             :     ITransferStrategyBase transferStrategy</span>
<span id="L334"><span class="lineNum">     334</span>                 :             :   ) internal {</span>
<span id="L335"><span class="lineNum">     335</span>                 :<span class="tlaGNC">          44 :     require(address(transferStrategy) != address(0), 'STRATEGY_CAN_NOT_BE_ZERO');</span></span>
<span id="L336"><span class="lineNum">     336</span>                 :<span class="tlaGNC">          44 :     require(_isContract(address(transferStrategy)) == true, 'STRATEGY_MUST_BE_CONTRACT');</span></span>
<span id="L337"><span class="lineNum">     337</span>                 :             : </span>
<span id="L338"><span class="lineNum">     338</span>                 :<span class="tlaGNC">          44 :     _transferStrategy[reward] = transferStrategy;</span></span>
<span id="L339"><span class="lineNum">     339</span>                 :             : </span>
<span id="L340"><span class="lineNum">     340</span>                 :<span class="tlaGNC">          44 :     emit TransferStrategyInstalled(reward, address(transferStrategy));</span></span>
<span id="L341"><span class="lineNum">     341</span>                 :             :   }</span>
<span id="L342"><span class="lineNum">     342</span>                 :             : </span>
<span id="L343"><span class="lineNum">     343</span>                 :             :   /**</span>
<span id="L344"><span class="lineNum">     344</span>                 :             :    * @dev Update the Price Oracle of a reward token. The Price Oracle must follow Chainlink IEACAggregatorProxy interface.</span>
<span id="L345"><span class="lineNum">     345</span>                 :             :    * @notice The Price Oracle of a reward is used for displaying correct data about the incentives at the UI frontend.</span>
<span id="L346"><span class="lineNum">     346</span>                 :             :    * @param reward The address of the reward token</span>
<span id="L347"><span class="lineNum">     347</span>                 :             :    * @param rewardOracle The address of the price oracle</span>
<span id="L348"><span class="lineNum">     348</span>                 :             :    */</span>
<span id="L349"><span class="lineNum">     349</span>                 :             : </span>
<span id="L350"><span class="lineNum">     350</span>                 :<span class="tlaGNC">          22 :   function _setRewardOracle(address reward, IEACAggregatorProxy rewardOracle) internal {</span></span>
<span id="L351"><span class="lineNum">     351</span>                 :<span class="tlaGNC">          44 :     require(rewardOracle.latestAnswer() &gt; 0, 'ORACLE_MUST_RETURN_PRICE');</span></span>
<span id="L352"><span class="lineNum">     352</span>                 :<span class="tlaGNC">          44 :     _rewardOracle[reward] = rewardOracle;</span></span>
<span id="L353"><span class="lineNum">     353</span>                 :<span class="tlaGNC">          44 :     emit RewardOracleUpdated(reward, address(rewardOracle));</span></span>
<span id="L354"><span class="lineNum">     354</span>                 :             :   }</span>
<span id="L355"><span class="lineNum">     355</span>                 :             : }</span>
        </pre>
              </td>
            </tr>
          </table>
          <br>

          <table width="100%" border=0 cellspacing=0 cellpadding=0>
            <tr><td class="ruler"><img src="../../../../../../../glass.png" width=3 height=3 alt=""></td></tr>
            <tr><td class="versionInfo">Generated by: <a href="https://github.com//linux-test-project/lcov" target="_parent">LCOV version 2.0-1</a></td></tr>
          </table>
          <br>

</body>
</html>
